<template>
  <li
    class="songitem"
    :class="{ current: song.id === currentPlaySongId, playing: playing }"
    @click="$emit('update:current-play-song', song)"
  >
    <span class="order" v-if="order">{{ order }}</span>
    <div class="detail">
      <h5>{{ song.name }}</h5>
      <div class="info">
        <span>
          <span
            v-for="(artist, index) in song.song ? song.song.artists : song.ar"
            :key="index"
            class="artist"
            >{{ artist.name }}</span
          >
        </span>
        <span>{{ song.song ? song.song.album.name : song.al.name }}</span>
      </div>
    </div>

    <span class="icon">
      <div class="play">
        <svg
          t="1635923962993"
          viewBox="0 0 1024 1024"
          version="1.1"
          xmlns="http://www.w3.org/2000/svg"
          p-id="1460"
          width="14"
          height="14"
        >
          <path
            d="M798.579835 553.363155L270.865448 897.201157c-28.647146 18.857264-67.084174 9.067382-67.084174-45.987159V174.194878c0-55.415791 35.836026-62.965921 67.084174-45.914909l527.714387 343.765752c29.550272 19.83264 30.417272 59.786919 0 81.317434zM259.37769 828.708107l500.692867-315.985606L259.37769 196.700769V828.708107z"
            fill="#ccc"
            p-id="1461"
          ></path>
        </svg>
      </div>

      <div class="donghua">
        <span></span>
        <span></span>
        <span></span>
      </div>
    </span>
  </li>
</template>

<script>
export default {
  props: {
    song: Object,
    order: Number,
    currentPlaySongId: [Number, String],
    playing: Boolean,
  },
};
</script>

<style lang="less" scoped>
@import "../assets/var.less";
@keyframes loading {
  from {
    // height: 20%;
    transform: scaleY(0.2);
  }
  to {
    // height: 100%;
    transform: scaleY(1);
  }
}
.songitem {
  border-bottom: 1px solid rgba(223, 222, 222, 0.575);
  padding-bottom: 10px;
  display: flex;
  margin: 10px;
  align-items: center;
  .order {
    width: 30px;
    font-size: 18px;
  }
  .detail {
    flex: 1;
    h5 {
      font-size: 18px;
      line-height: 26px;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }
    .info {
      font-size: 14px;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
      overflow: hidden;
      color: rgb(161, 161, 161);
      .artist {
        &::after {
          margin: 0 5px;
          content: "/";
        }
        &:last-of-type {
          //   background: red;
          &::after {
            content: "-";
          }
        }
      }
    }
  }

  .icon {
    width: 40px;
    height: 40px;
    // background: red;
    display: flex;
    border-radius: 50%;
    justify-content: center;
    align-items: center;
    .play {
      width: 60%;
      height: 60%;
      border: 1px solid #ccc;
      border-radius: 50%;
      display: flex;
      justify-content: center;
      align-items: center;
      // padding: 10px;
      svg {
        transform: translateX(1px);
      }
    }
  }

  &.current {
    .icon {
      // background: blue;
      .play {
        display: none;
      }
      .donghua {
        display: flex;
        height: 50%;
        width: 50%;
        justify-content: space-between;
        span {
          width: 20%;
          height: 100%;
          display: block;
          background: @red;
          animation: loading 0.6s linear infinite alternate;
          animation-play-state: paused;
          transform-origin: bottom;
          &:nth-child(1) {
            animation-delay: -0.4s;
          }
          &:nth-child(2) {
            animation-delay: -0.2s;
          }
        }
      }
    }

    &.playing {
      .icon {
        .donghua {
          span {
            animation-play-state: running;
          }
        }
      }
    }
  }
}
</style>
